#ifndef __GENSTAT_H__
#define __GENSTAT_H__

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "deme.h"
#include "arrays.h"
#include "cstring.h"

typedef MY_TArrayAsVector<int> THIST;

struct summary_stats {
	int num_haps;
	int num_private_haps;
 	int seg_sites;
  	double pairws_dif;
   double hap_div;
   double nuc_div;
   double tajd;
   //char hap_freq[20];
   //char mut_size[20];
   THIST mismatch;
};

class T_HAP {
  public:
	TIntVect* hap;
	int n;
	int first_deme;
	bool is_private;
	~T_HAP() {;};
   T_HAP() { n=0; first_deme=-1; is_private=1; }
   int operator==(const T_HAP& H) {
    	int *site1=hap->begin(), *site2=H.hap->begin();
    	while(site1<hap->end())
    		if(*site1++!=*site2++) return 0;
      return 1;
    }
    int operator<(const T_HAP& H) {return 0; }
};

//Christian: a class for parameter approximation
class TPrior {
   private :
      double min;
      double max;
      void* memloc1;
      void* memloc2;
   public :
      TPrior(double mn, double mx, void *x) {
         min=mn; max=mx; memloc1=x; memloc2=NULL;
      }
      TPrior(void) {
         min=0; max=0; memloc1=NULL; memloc2=NULL;
      }
      friend istream& operator >> (istream& is, TPrior& P);
      void SetLoc1(void *x) {memloc1=x;}
      void SetLoc2(void *x) {memloc2=x;}
      void Print(void) { printf("[%f to %f] at 0x%X and 0x%X",min,max,memloc1,memloc2); }
      double pick(void) {
         long x=clock();
         float y=ran3(&x);
         y=y*(max-min)+min;
         return y;
      }
};
extern istream& operator>>(istream& is, TPrior& P);
TPrior* BayesRead(void *buf,istream *ifs,int type);

typedef MY_TSArrayAsVector<T_HAP>  THapArray;

void CalcStats(THapArray *haps, summary_stats *st, const Mut_Type data_type);
void CalcInterStats(THapArray *h1, THapArray *h2, summary_stats *st, const Mut_Type data_type);

#endif

